package com.aiti.lulian.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.aiti.base.core.base.controller.WebController;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.dto.CardBusinessCollaboratorDto;
import com.aiti.lulian.dto.CommunicateInfoDto;
import com.aiti.lulian.dto.CommunicateInfoSaveDto;
import com.aiti.lulian.entity.CardBusinessCollaborator;
import com.aiti.lulian.entity.CommunicateInfo;
import com.aiti.lulian.service.CardBusinessCollaboratorService;
import com.aiti.lulian.service.ICommunicateInfoService;
import com.aiti.lulian.vo.CommunicateInfoExportVo;
import com.aiti.lulian.vo.CommunicateInfoVo;
import com.aiti.lulian.vo.EmployeeOpportunityCountVo;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Slf4j
@Api(tags = "商机协作人控制层")
@RestController
@RequestMapping("business/collaborator")
public class CardBusinessCollaboratorController extends WebController {


    @Autowired
    private CardBusinessCollaboratorService businessCollaboratorService;




    @ApiOperation("新增商机协作人")
    @PostMapping("deal")
    public Message dealCollaborator(@RequestBody CardBusinessCollaboratorDto dto) {


        return businessCollaboratorService.dealCollaborator(dto);
    }

    @ApiOperation("展示所选商机的协作人")
    @PostMapping("collaboratorList")
    public Message collaboratorList(@RequestBody CardBusinessCollaboratorDto dto) {
        List<String> businessIdList = dto.getBusinessIdList();
        List<CardBusinessCollaborator> collaboratorList = businessCollaboratorService.list(new LambdaQueryWrapper<CardBusinessCollaborator>().select(CardBusinessCollaborator::getUserId,CardBusinessCollaborator::getUserName).in(CardBusinessCollaborator::getRelateId,businessIdList).groupBy(CardBusinessCollaborator::getUserId).groupBy(CardBusinessCollaborator::getUserName));
        return Message.success(collaboratorList);

    }




}